package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.PageResponseResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 频道
 */
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询所有频道
     */
    @GetMapping("/channels")
    public ResponseResult<List<WmChannel>> findList() {
        return ResponseResult.okResult(wmChannelService.list());
    }

    //删除频道
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id) {
        return ResponseResult.okResult(wmChannelService.removeById1(id));
    }

    //保存频道
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel) {
        return ResponseResult.okResult(wmChannelService.save(wmChannel));
    }

    //查询频道
    @PostMapping("/list")
    public PageResponseResult listChannel(@RequestBody WmChannelDto wmChannelDto) {
        return wmChannelService.listChannel(wmChannelDto);
    }

    //更新频道
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel wmChannel) {
        return ResponseResult.okResult(wmChannelService.updateChannel(wmChannel));
    }
}
